1 /*
2 Copyright (c)
2014 Andrew Jones, Dario Seyb
3  Based
on 'Spriter2Unity' python code by Malhavok
4
5 Permission
is hereby granted, free of charge, to any person obtaining a copy
6 of
this software and associated documentation files (the "Software"), to deal
7 in
the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software
is
10 furnished to
do so, subject to the following conditions:
11
12 The above copyright notice and
this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */

23 using
System;
24 using
System.Collections.Generic;
25 using
System.Linq;
26 using
System.Text;
27 using
System.Xml;
28
29 namespace
Assets.ThirdParty.Spriter2Unity.Editor.Spriter
30 {
31     
public class Timeline : KeyElem
32     {
33         
public const string XmlKey = "timeline";
34
35         
public SpriterAnimation Animation { get; private set; }
36         
public string Name { get; private set; }
37         
public ObjectType ObjectType { get; private set; }
38         
public IEnumerable<TimelineKey> Keys { get{return keys;} }
39
40         
public Timeline(XmlElement element, SpriterAnimation animation)
41             :
base(element)
42         {
43             Parse (element, animation);
44         }
45
46         
protected virtual void Parse(XmlElement element, SpriterAnimation animation)
47         {
48             Animation = animation;
49             Name = element.GetString(
"name", "");
50
51             ObjectType = ObjectType.Parse(element);
52
53             
var children = element.GetElementsByTagName(TimelineKey.XmlKey);
54             
foreach (XmlElement childElement in children)
55             {
56                 keys.Add(GetKey(childElement));
57             }
58         }
59
60         
public TimelineKey GetKey(int id)
61         {
62             
return Keys.Where(key => key.Id == id).FirstOrDefault();
63         }
64
65         
private TimelineKey GetKey(XmlElement element)
66         {
67             
//Check if key is sprite or bone
68             
var bone = element[BoneTimelineKey.XmlKey];
69             
if(bone != null)
70             {
71                 
return new BoneTimelineKey(element, this);
72             }
73             
else
74             {
75                 
var obj = element[SpriteTimelineKey.XmlKey];
76                 
if(obj != null)
77                 {
78                     
var objType = ObjectType.Parse(obj);
79                     
if (objType == ObjectType.Sprite)
80                     {
81                         
return new SpriteTimelineKey(element, this);
82                     }
83                 }
84             }
85             
return null;
86         }
87         
private List<TimelineKey> keys = new List<TimelineKey>();
88     }
89 }


Check if key is sprite or bone




Trò chơi đua xe động vật trong UNITY Engine 114.696 lượt xem

Gõ tìm kiếm nhanh...